﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;
using Coding4Fun.Kinect.Wpf;

namespace Hugo
{
    class KinectCursorController
    {
        /*
        private Runtime nui;

        public void moveUp()
        {
            if (nui != null)
            {
                nui.NuiCamera.ElevationAngle += 5;
            }
        }

        public void moveDown()
        {
            if (nui != null)
            {
                nui.NuiCamera.ElevationAngle -= 5;
            }
        }

        private HandCursor Cursor;

        void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            SkeletonFrame allSkeletons = e.SkeletonFrame;

            SkeletonData skeleton = (from s in allSkeletons.Skeletons
                                     where s.TrackingState == SkeletonTrackingState.Tracked
                                     select s).FirstOrDefault();

            if (skeleton == null) {
                return; 
            }

            
            Joint j = skeleton.Joints[JointID.HandRight];
            if (!GlobalSettings.isRightHanded) {
                j = skeleton.Joints[JointID.HandLeft];
            }

            double width = System.Windows.SystemParameters.PrimaryScreenWidth;
            double height = System.Windows.SystemParameters.PrimaryScreenHeight;
            var scaledJoint = j.ScaleTo((int)width, (int)height, .3f, .5f);

            this.Cursor.setCursorPosition(scaledJoint.Position.X, scaledJoint.Position.Y);
        }

        public KinectCursorController(HandCursor cursor) {

            this.Cursor = cursor;

            nui = Runtime.Kinects[0];

            //Inicjalizacja trybu Skeletal tracking
            nui.Initialize(RuntimeOptions.UseSkeletalTracking);

            //Musi byc ustawione na true i wywolane zaraz po inicjalizacji NUI
            nui.SkeletonEngine.TransformSmooth = true;

            //Dodatkowe parametry pozwalajace na usuniecie drgan
            var parameters = new TransformSmoothParameters
            {
                Smoothing = 0.75f,
                Correction = 0.0f,
                Prediction = 0.0f,
                JitterRadius = 0.05f,
                MaxDeviationRadius = 0.04f
            };

            //Dodanie zdarzenia, przechwytujacego dane
            nui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady);
        }
         */
    }
}
